-- NewTeamMemberHeadRender 对 BaseTeamMemberHead.csb 的解析
-- 队伍成员头像render

local AvatarIconNode = require("app.widget.AvatarIconNode")

local ClassRef = app.mvc.createRenderClass(...)

-- UserBaseInfo like
function ClassRef.create(node)
	local sprite = ClassRef.extend(node or cc.CSLoader:createNode(Res.BaseTeamMemberHead))
	if node == nil then
		ccui.Helper:doLayout(sprite)
	end
	sprite:init()
	return sprite
end

function ClassRef:init(data)
	self.super.init(self, data)

	self._ui.Panel_lv:setVisible(true)
	self._ui.class_icon:setVisible(true)
	self._avatarIconNode = AvatarIconNode.new(self._ui.Panel, "icon", "mask")

	display.uiAddClick(self._ui.Panel, function(sender)
			executeFunc(self._onClick, self, self._data)
		end)
	self:refresh()
end

function ClassRef:getPanelSize()
	return self._ui.Panel:getContentSize()
end

function ClassRef:refresh()
	if self._data then
		self:setVisible( true )

		self._ui.num:setString(self._data.lv)
		if not self._data.classID then
			self._avatarIconNode:update(UD:getAvatarParams())
		else
			self._avatarIconNode:update( self._data )
			self._ui.class_icon:loadTexture( GD:getClassIcon( tonumber( self._data.classID ) , 2 ) )
		end
	else
		self:setVisible( false )
	end
end

function ClassRef:setIcon(url)
	self:setIconVisible(true)
	self._ui.icon:loadTexture(url)
end
function ClassRef:setIconVisible(b)
	self._ui.icon:setVisible(b)
end

function ClassRef:setClassIcon(url)
	self:setClassIconVisible(true)
	self._ui.class_icon:loadTexture(url)
end
function ClassRef:setClassIconVisible(b)
	self._ui.class_icon:setVisible(b)
end

-- 设置品质框
function ClassRef:setQualityIcon( quality )
	quality = quality or 1
	self._ui.bg:loadTexture( Res.Quality_Partner_Icon[quality] )
end

-- 设置等级
function ClassRef:setLv( lvStr )
	lvStr = lvStr or ""
	self._ui.num:setString( lvStr )
end

function ClassRef:setLvVisible(b)
	self._ui.Panel_lv:setVisible(b)
end

function ClassRef:onClick(cb)
	self._onClick = cb
end

return ClassRef
